package com.archie.xunji.guanzhu.asyncs;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.ListView;
import com.archie.xunji.guanzhu.adapters.PeopleAdapter;
import com.archie.xunji.guanzhu.entitys.People;
import com.archie.xunji.guanzhu.tools.HttpUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

/**
 * Created by xqx on 2015/11/9.
 */
public class GetPeopleDataAsync extends AsyncTask<String,Void,String>{
    private ListView listView;
    private PeopleAdapter adapter;
    private Context context;
    private List<People> data;
    public GetPeopleDataAsync(Context context,ListView listView) {
        this.listView = listView;
        this.context = context;
    }

    @Override
    protected String doInBackground(String... params) {
        String url = null;
        if (params[0] != null) {
            HashMap<String,String> map = new HashMap<String, String>();
            map.put("userinfoid", "26099");
            map.put("appuserid","43481");
            map.put("t","20151110121425");
            map.put("token","6D17412EF7C602790CBE216D2BFDFE8AA8E990D0");
            map.put("sid","Co0gh2v0Nr");
            map.put("imei","9692B6993494E9324B7F9560912242B7");
            map.put("os","Android+4.4.4");
            map.put("key","WANDOUJIA");
            map.put("type","1");

            try {
                url = HttpUtils.sendByPost(params[0], map, "utf-8");

            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        return url;
    }

    @Override
    protected void onPostExecute(String s) {
        if (s != null) {
            data = People.getDataList(s);
            adapter = new PeopleAdapter(data,context);
            listView.setAdapter(adapter);

        }
    }
}
